//
//  PropertycostsPaymentViewController.m
//  WisdomCommunity
//
//  Created by Yahaong on 16/7/28.
//  Copyright © 2016年 zonten. All rights reserved.
//

#import "PropertycostsPaymentViewController.h"
#import "WYUserView.h"
#import "YHMarcros.h"

@interface PropertycostsPaymentViewController ()
@property(nonatomic, strong)WYUserView *topView;
/** 支付明细 */
@property(nonatomic, strong)UIView *payDetailView;
/** 支付方式 */
@property(nonatomic, strong)UIView *payMethodView;
@property(nonatomic, strong)UIView *bottomView;
/** 优惠信息 */
@property(nonatomic, strong)UIButton *discountButton;

/** 银联支付 */
@property(nonatomic, strong)UIButton *unionPayButton;
@property(nonatomic, strong)UIButton *unionPaySelectButton;
/** 支付宝支付 */
@property(nonatomic, strong)UIButton *zhifubaoButton;
@property(nonatomic, strong)UIButton *zhifubaoSelectButton;
/** 微信支付 */
@property(nonatomic, strong)UIButton *weixinButton;
@property(nonatomic, strong)UIButton *weixinSelectButton;
/** 合计 */
@property(nonatomic, strong)UILabel *totalLabel;
/** 确认支付 */
@property(nonatomic, strong)UIButton *sureButton;
@end

@implementation PropertycostsPaymentViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"物业缴费";
    self.edgesForExtendedLayout = UIRectEdgeNone;
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.view.backgroundColor = kBgColor;
    [self.view addSubview:self.topView];
    [self.topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.top.equalTo(self.view);
        make.height.equalTo(kIphoneSize_Height(90));
    }];
    UILabel *label = [[UILabel alloc]init];
    label.textColor = RGBColor(102, 102, 102);
    label.text = @"缴费明细";
    [self.view addSubview:label];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.topView.bottom).offset(10);
        make.leading.equalTo(self.view).offset(10);
    }];
    [self.view addSubview:self.payDetailView];
    [self.payDetailView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(label.bottom).offset(10);
        make.leading.trailing.equalTo(self.view);
    }];
    UILabel *amountLabel =  [[UILabel alloc]init];
    amountLabel.textColor = RGBColor(102, 102, 102);
    amountLabel.text = @"缴费金额";
    [self.payDetailView addSubview:amountLabel];
    [amountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(label.bottom);
        make.leading.equalTo(self.payDetailView).offset(10);
        make.height.equalTo(kIphoneSize_Height(47));
        
    }];
    UILabel *moneyLabel =  [[UILabel alloc]init];
    moneyLabel.textColor = RGBColor(102, 102, 102);
    moneyLabel.text = @"￥224";
    [self.payDetailView addSubview:moneyLabel];
    [moneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(amountLabel);
        make.trailing.equalTo(self.view).offset(-10);
        make.height.equalTo(47);
    }];
    UIView *paySplitView = [[UIView alloc]init];
    paySplitView.backgroundColor = kSplitLineColor;
    [self.payDetailView addSubview:paySplitView];
    [paySplitView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.equalTo(self.payDetailView);
        make.height.equalTo(1);
        make.top.equalTo(amountLabel.bottom);
    }];
    
    UILabel *disacountLabel =  [[UILabel alloc]init];
    disacountLabel.textColor = RGBColor(102, 102, 102);
    disacountLabel.text = @"优惠金额";
    [self.payDetailView addSubview:disacountLabel];
    [disacountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(paySplitView.bottom).offset(10);
        make.leading.equalTo(amountLabel);
    }];
    [self.payDetailView addSubview:self.discountButton];
    [self.discountButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(disacountLabel);
        make.top.equalTo(disacountLabel.bottom).offset(10);
    }];
    
    UILabel *disacountMoneyLabel =  [[UILabel alloc]init];
    disacountMoneyLabel.textColor = RGBColor(102, 102, 102);
    disacountMoneyLabel.text = @"-￥2.00";
    [self.payDetailView addSubview:disacountMoneyLabel];
    [disacountMoneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(disacountLabel);
        make.trailing.equalTo(self.view).offset(-10);
        
        
    }];
    UIView *paySplitView1 = [[UIView alloc]init];
    paySplitView1.backgroundColor = kSplitLineColor;
    [self.payDetailView addSubview:paySplitView1];
    [paySplitView1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.equalTo(self.payDetailView);
        make.height.equalTo(1);
        make.top.equalTo(self.discountButton.bottom).offset(10);
    }];
    
    UILabel *canuseLabel =  [[UILabel alloc]init];
    canuseLabel.textColor = RGBColor(102, 102, 102);
    canuseLabel.text = @"可用20积分抵抗￥0.2元";
    [self.payDetailView addSubview:canuseLabel];
    [canuseLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(paySplitView1.bottom).offset(10);
        make.leading.equalTo(self.payDetailView).offset(10);
    }];
    UISwitch *sc = [[UISwitch alloc]init];
    sc.onTintColor = kGlobalRedColor;
    [self.payDetailView addSubview:sc];
    [sc mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(canuseLabel);
        make.trailing.equalTo(self.payDetailView).offset( - 10);
        
    }];
    
    [self.payDetailView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(canuseLabel.bottom).offset(10);
    }];
    UILabel *payMethodLabel =  [[UILabel alloc]init];
    payMethodLabel.textColor = RGBColor(102, 102, 102);
    payMethodLabel.text = @"选择支付方式";
    [self.view addSubview: payMethodLabel];
    [payMethodLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.payDetailView.bottom).offset(10);
        make.leading.equalTo(self.view).offset(10);
    }];
    
    
    [self.view addSubview:self.payMethodView];
    [self.payMethodView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(payMethodLabel.bottom).offset(10);
        make.leading.trailing.equalTo(self.view);
    }];

    [self.payMethodView addSubview:self.unionPayButton];
    [self.unionPayButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.payMethodView).offset(10);
        make.leading.equalTo(self.payMethodView).offset(10);
    }];
    [self.payMethodView addSubview:self.unionPaySelectButton];
    [self.unionPaySelectButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.unionPayButton);
        make.trailing.equalTo(self.payMethodView).offset(-10);
    }];
    
    
    UIView *unionPaySplitView = [[UIView alloc]init];
    unionPaySplitView.backgroundColor = kSplitLineColor;
    [self.payMethodView addSubview:unionPaySplitView];
    [unionPaySplitView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.equalTo(self.payMethodView);
        make.height.equalTo(1);
        make.top.equalTo(self.unionPayButton.bottom).offset(10);
    }];
    
    
    [self.payMethodView addSubview:self.zhifubaoButton];
    [self.zhifubaoButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(unionPaySplitView).offset(10);
        make.leading.equalTo(self.payMethodView).offset(10);
    }];
    
    [self.payMethodView addSubview:self.zhifubaoSelectButton];
    [self.zhifubaoSelectButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.zhifubaoButton);
        make.trailing.equalTo(self.payMethodView).offset(-10);
    }];
    UIView *zhifubaoSplitView = [[UIView alloc]init];
    zhifubaoSplitView.backgroundColor = kSplitLineColor;
    [self.payMethodView addSubview:zhifubaoSplitView];
    [zhifubaoSplitView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.equalTo(self.payMethodView);
        make.height.equalTo(1);
        make.top.equalTo(self.zhifubaoButton.bottom).offset(10);
    }];
    
    
    [self.payMethodView addSubview:self.weixinButton];
    [self.weixinButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(zhifubaoSplitView).offset(10);
        make.leading.equalTo(self.payMethodView).offset(10);
    }];
    [self.payMethodView addSubview:self.weixinSelectButton];
    [self.weixinSelectButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.weixinButton);
        make.trailing.equalTo(self.payMethodView).offset(-10);
    }];
    [self.payMethodView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.weixinButton.bottom).offset(10);
    }];
    [self.view addSubview:self.bottomView];
    [self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) {

        make.bottom.leading.trailing.equalTo(self.view);
        make.height.equalTo(kIphoneSize_Height(50));
        
    }];
    [self.bottomView addSubview:self.totalLabel];
    [self.totalLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.bottomView);
        make.leading.equalTo(self.bottomView).offset(10);
    }];
    [self.bottomView addSubview:self.sureButton];
    [self.sureButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.trailing.bottom.equalTo(self.bottomView);
        make.width.equalTo(80);
    }];
    
}
- (void)viewDidLayoutSubviews{
    [super viewDidLayoutSubviews];

    self.unionPayButton.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, -10);
    self.zhifubaoButton.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, -10);
    self.weixinButton.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, -10);
    
}
- (void)payMenthodselect:(UIButton *)button
{
    button.selected= !button.selected;
}
#pragma mark - lazy loading
- (UIView *)topView
{
    if (!_topView) {
        _topView = [[WYUserView alloc]init];
    }
    return _topView;
}

- (UIButton *)discountButton
{
    if (!_discountButton) {
        _discountButton = [[UIButton alloc]init];
        [_discountButton setImage:[UIImage imageNamed:@"property_icon_sale"] forState:UIControlStateNormal];
        [_discountButton setTitle:@"折扣优惠9.8折，最高优惠 100 元" forState:UIControlStateNormal];
        [_discountButton setTitleColor:RGBColor(102, 102, 102) forState:UIControlStateNormal];
        
    }
    return _discountButton;
}

- (UIView *)payDetailView
{
    if (!_payDetailView) {
        _payDetailView = [[UIView alloc]init];
        _payDetailView.backgroundColor = [UIColor whiteColor];
    }
    return _payDetailView;
}
- (UIView *)payMethodView
{
    if (!_payMethodView) {
        _payMethodView = [[UIView alloc]init];
        _payMethodView.backgroundColor = [UIColor whiteColor];
    }
    return _payMethodView;
}

- (UIView *)bottomView
{
    if (!_bottomView) {
        _bottomView = [[UIView alloc]init];
        _bottomView.backgroundColor = [UIColor whiteColor];
    }
    return _bottomView;
}

- (UIButton *)unionPayButton
{
    if (!_unionPayButton) {
        _unionPayButton = [[UIButton alloc]init];
        [_unionPayButton setImage:[UIImage imageNamed:@"property_icon_unionPay"] forState:UIControlStateNormal];
        [_unionPayButton setTitle:@"银联支付"forState:UIControlStateNormal];
        [_unionPayButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    }
    return _unionPayButton;
}
- (UIButton *)zhifubaoButton
{
    if (!_zhifubaoButton) {
        _zhifubaoButton = [[UIButton alloc]init];
        [_zhifubaoButton setImage:[UIImage imageNamed:@"property_icon_zhifubao"] forState:UIControlStateNormal];
        [_zhifubaoButton setTitle:@"支付宝"forState:UIControlStateNormal];
        [_zhifubaoButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    }
    return _zhifubaoButton;
}
- (UIButton *)weixinButton
{
    if (!_weixinButton) {
        _weixinButton = [[UIButton alloc]init];
        [_weixinButton setImage:[UIImage imageNamed:@"property_icon_weixin"] forState:UIControlStateNormal];
        [_weixinButton setTitle:@"微信支付"forState:UIControlStateNormal];
        [_weixinButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    }
    return _weixinButton;
}
- (UILabel *)totalLabel
{
    if (!_totalLabel) {
        _totalLabel = [[UILabel alloc]init];
        _totalLabel.text = @"合计:￥238.80";
    }
    return _totalLabel;
}
- (UIButton *)sureButton
{
    if (!_sureButton) {
        _sureButton = [[UIButton alloc]init];
        _sureButton.backgroundColor = kGlobalRedColor;
        [_sureButton setTitle:@"确认支付"forState:UIControlStateNormal];
    }
    return _sureButton;
}

- (UIButton *)weixinSelectButton
{
    if (!_weixinSelectButton) {
        _weixinSelectButton = [[UIButton alloc]init];
        [_weixinSelectButton setImage:[UIImage imageNamed:@"property_icon_normal"] forState:UIControlStateNormal];
        [_weixinSelectButton setImage:[UIImage imageNamed:@"property_icon_selected"] forState:UIControlStateSelected];
        [_weixinSelectButton addTarget:self action:@selector(payMenthodselect:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _weixinSelectButton;
}
- (UIButton *)unionPaySelectButton
{
    if (!_unionPaySelectButton) {
        _unionPaySelectButton = [[UIButton alloc]init];
        [_unionPaySelectButton setImage:[UIImage imageNamed:@"property_icon_normal"] forState:UIControlStateNormal];
        [_unionPaySelectButton setImage:[UIImage imageNamed:@"property_icon_selected"] forState:UIControlStateSelected];
        [_unionPaySelectButton addTarget:self action:@selector(payMenthodselect:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _unionPaySelectButton;
}
- (UIButton *)zhifubaoSelectButton
{
    if (!_zhifubaoSelectButton) {
        _zhifubaoSelectButton = [[UIButton alloc]init];
        [_zhifubaoSelectButton setImage:[UIImage imageNamed:@"property_icon_normal"] forState:UIControlStateNormal];
        [_zhifubaoSelectButton setImage:[UIImage imageNamed:@"property_icon_selected"] forState:UIControlStateSelected];
        [_zhifubaoSelectButton addTarget:self action:@selector(payMenthodselect:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _zhifubaoSelectButton;
}
@end
